package J11_16;

import java.util.HashSet;
import java.util.Set;

public class Test {
        public static boolean isHappy(int n) {
            Set<Integer> set = new HashSet<>();
            while (true) {
                if (n == 1) {
                    return true;
                } else {
                    if (set.contains(n)) {
                        return false;
                    } else  {
                        set.add(n);
                        n = getSun(n);
                    }
                }
            }
        }
        public static int getSun(int n) {
            int res = 0;
            while (n > 0) {
                int t = n % 10;
                res += t * t;
                n /= 10;
            }
            return res;
        }

}
